package edu.uoc.tdp.client.conexio;

import edu.uoc.tdp.common.EOlympicsHelper;
import edu.uoc.tdp.common.TDSLanguageUtils;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;

/**
 *
 * @author Grup TDP 1X4J
 */
public class PantallaMissatge extends javax.swing.JDialog {

    /**
     * Creates new form PantallaMissatge
     */
    public PantallaMissatge(java.awt.Frame parent, boolean modal, 
                            String missAvis, String missPreg) {
        super(parent, modal);
        
        TDSLanguageUtils.setDefaultLanguage("edu/uoc/tdp/i18n/messages");
        initComponents();
        
        this.setLocationRelativeTo(parent);
        
        setTitle(TDSLanguageUtils.getMessage("connexio.pantalla.pantmiss.titol"));
        jBotoAcceptar.setText(TDSLanguageUtils.getMessage("connexio.pantalla.pantmiss.btnAcceptar")); 
        jBotoCancellar.setText(TDSLanguageUtils.getMessage("connexio.pantalla.pantmiss.btnCancellar"));
        
        jLabAvis.setText(missAvis);
        jLabPregunta.setText(missPreg);

        // Tanca la finestra si es pulsa Esc
        String cancelName = "cancel";
        InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
        ActionMap actionMap = getRootPane().getActionMap();
        actionMap.put(cancelName, new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                doClose(EOlympicsHelper.RET_CANCEL);
            }
        });
    }

    /**
     * @return the return status of this dialog - one of RET_OK or RET_CANCEL
     */
    public int getReturnStatus() {
        return returnStatus;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBotoAcceptar = new javax.swing.JButton();
        jBotoCancellar = new javax.swing.JButton();
        jLabAvis = new javax.swing.JLabel();
        jLabelIcona = new javax.swing.JLabel();
        jLabPregunta = new javax.swing.JLabel();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jBotoAcceptar.setText("Acceptar");
        jBotoAcceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBotoAcceptarActionPerformed(evt);
            }
        });

        jBotoCancellar.setText("Cancel·lar");
        jBotoCancellar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBotoCancellarActionPerformed(evt);
            }
        });

        jLabAvis.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabelIcona.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ImatgeAlerta64.png"))); // NOI18N

        jLabPregunta.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabPregunta.setFocusable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(295, Short.MAX_VALUE)
                        .addComponent(jBotoAcceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBotoCancellar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabelIcona)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabAvis, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabPregunta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBotoAcceptar, jBotoCancellar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelIcona)
                        .addGap(0, 24, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabAvis, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabPregunta, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jBotoCancellar)
                            .addComponent(jBotoAcceptar))))
                .addContainerGap())
        );

        getRootPane().setDefaultButton(jBotoAcceptar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBotoAcceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBotoAcceptarActionPerformed
        doClose(EOlympicsHelper.RET_OK);
    }//GEN-LAST:event_jBotoAcceptarActionPerformed
    
    private void jBotoCancellarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBotoCancellarActionPerformed
        doClose(EOlympicsHelper.RET_CANCEL);
    }//GEN-LAST:event_jBotoCancellarActionPerformed

    /**
     * Closes the dialog
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        doClose(EOlympicsHelper.RET_CANCEL);
    }//GEN-LAST:event_closeDialog
    
    private void doClose(int retStatus) {
        returnStatus = retStatus;
        setVisible(false);
        dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBotoAcceptar;
    private javax.swing.JButton jBotoCancellar;
    private javax.swing.JLabel jLabAvis;
    private javax.swing.JLabel jLabPregunta;
    private javax.swing.JLabel jLabelIcona;
    // End of variables declaration//GEN-END:variables
    private int returnStatus = EOlympicsHelper.RET_CANCEL;
}
